package com.wanmait.myhouse.managerController;

import com.wanmait.myhouse.dao.MediatorDAO;
import com.wanmait.myhouse.dao.MediatorFeedDAO;
import com.wanmait.myhouse.vo.FeedBack;
import com.wanmait.myhouse.vo.Mediator;
import com.wanmait.myhouse.vo.MediatorFeed;
import com.wanmait.myhouse.vo.Pager;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("manager")
public class MediatorFeedBackController {
    @GetMapping("mediatorFeedBack")
    public String mediatorFeedBack(Model model , Integer pno){
        MediatorFeedDAO mediatorFeedDAO = new MediatorFeedDAO();
        MediatorDAO mediatorDAO = new MediatorDAO();
        Pager pager = new Pager();
        if (pno == null){
            pno = 1;
        }
        pager.setPageNO(pno);
        pager.setPageSize(4);
        int total = mediatorFeedDAO.getTotal();
        int pageCount = total/pager.getPageSize()+(total%pager.getPageSize()==0?0:1);
        pager.setPageCount(pageCount);
        model.addAttribute("pager",pager);
        List<MediatorFeed> mediatorFeedList = mediatorFeedDAO.selectAll(pager);
        for (MediatorFeed mediatorFeed : mediatorFeedList){
            Mediator mediator = mediatorDAO.findById(mediatorFeed.getMediatorId());
            mediatorFeed.setMediator(mediator);
        }
        model.addAttribute("mediatorFeedList",mediatorFeedList);
        return "/manager/mediatorFeedBack";
    }
}
